package com.IO;

import java.io.*;

public class CopyFile {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\下载\\file\\file1");
        String name = file.getName();
        File fileDest = new File("D:\\下载\\file\\file4", name);
        if (!fileDest.exists()) {
            fileDest.mkdirs();
        }
        File[] list = file.listFiles();
        for (File src:list) {
            String nm = src.getName();
            File dest = new File(fileDest, nm);
            copyFile(src, dest);
        }
    }

    private static void copyFile(File src ,File dest) throws IOException {
        BufferedInputStream bis=new BufferedInputStream((new FileInputStream(src)));
        BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(dest,true));
        byte[] bys=new byte[1024];
        int len;
        while((len=bis.read(bys))!=-1){
            bos.write(bys,0,len);
        }
        bis.close();
        bos.close();
    }
}
